** CODE for replication of "Interpersonal Resources and Insider/Outsider Dynamics in Party Office "
** Authors: Javier Martínez-Cantó and Tània Verge
** Journal: Comparative Political Studies (CPS)

** Before running this code, please see the "readme_replication" file for general instructions. 
** All procedures and analysis were executed using STATA 14.1

*****************************************************
*** Analysis 3: Gendered survival in party office ***
*****************************************************

*** Importing the dataset
clear 

use "data_necs.dta"

*** Installing required packages (if necesary)
*ssc install estout, replace
*ssc install blindschemes, replace
*ssc install coefplot, replace
*net install grc1leg, from(http://www.stata.com/users/vwiggins) replace

* set scheme plotplain

* Remove observations with missing data
drop if full==0

*** Declare the data to be survival data
stset nec_order_year, id(id_name_period) failure(nec_failure==1) 
drop if _t==.
stsum

*******************************************
*** Analysis 3 - Multivariate analysis  ***
*******************************************

* Globals capturing different sets of variables
global personal 							age university_degree isei 	
global family	 							childless	
global political_offices 					seniority_log national_politics_experience_log  
global inter_personal 						years_as_party_member_log youth_org leader_coincidence_log
global party_position 						party_hardcore 
global party_level	 						nato nec_election_mode  share_female_nec total_nec gender_internal_rules
global controls 							years_since_last_partyconference 
global party 								i.party 

global personal_ 							c.age c.university_degree c.isei
global family_	 							c.childless	
global political_offices_ 					c.seniority_log c.national_politics_experience_log  
global inter_personal_ 						c.years_as_party_member_log c.youth_org c.leader_coincidence_log 
global party_position_ 						c.party_hardcore 
global party_level_	 						c.nato c.nec_election_mode  c.share_female_nec c.total_nec c.gender_internal_rules
global controls_ 							c.years_since_last_partyconference 
global party_ 								i.party 

	
* Full sample, baseline regression models
stcox  i.gender 		 																																	,  vce(cluster party)
eststo model_survival1
stcox  i.gender 		 																									$party_level_ $controls_ $party_,  vce(cluster party)
eststo model_survival2
stcox  i.gender $personal_ 																									$party_level_ $controls_ $party_,  vce(cluster party)
eststo model_survival3
stcox  i.gender $political_offices_ $party_position_ 																		$party_level_ $controls_ $party_,  vce(cluster party)
eststo model_survival4
stcox  i.gender $inter_personal_ 																							$party_level_ $controls_ $party_,  vce(cluster party)
eststo model_survival5
stcox  i.gender $personal_ $political_offices_ $party_position_ $inter_personal_ 											$party_level_ $controls_ $party_,  vce(cluster party)
eststo model_survival6

* Sub-sample, baseline regression models
stcox  i.gender 		 																																	 if party<3402,  vce(cluster party)
eststo model_survival7
stcox  i.gender 		 																									$party_level_ $controls_ $party_  if party<3402,  vce(cluster party)
eststo model_survival8
stcox  i.gender $personal_ 																									$party_level_ $controls_ $party_  if party<3402,  vce(cluster party)
eststo model_survival9
stcox  i.gender $political_offices_ $party_position_ 																		$party_level_ $controls_ $party_  if party<3402,  vce(cluster party)
eststo model_survival10
stcox  i.gender $inter_personal_ 																							$party_level_ $controls_ $party_  if party<3402,  vce(cluster party)
eststo model_survival11
stcox  i.gender $family_																									$party_level_ $controls_ $party_  if party<3402,  vce(cluster party)
eststo model_survival12
stcox  i.gender $personal_ $political_offices_ $party_position_ $inter_personal_	$family_								$party_level_ $controls_ $party_  if party<3402,  vce(cluster party)
eststo model_survival13

* Gender differences (interaction models)
** Full sample
stcox  i.gender##($personal_ $political_offices_ $inter_personal_ $party_position_				$party_level_ $controls_ $party_),  vce(cluster party)
eststo model_survival14
estimates store model_survival14
** Sub-sample
stcox  i.gender##($personal_ $political_offices_ $inter_personal_ $party_position_	$family_	$party_level_ $controls_ $party_ ) if party<3402,  vce(cluster party)
eststo model_survival15
estimates store model_survival15

* Tables
esttab model_survival1 model_survival2 model_survival3 model_survival4 model_survival5 model_survival6, label mtitle("Model 1" "Model 2" "Model 3" "Model 4" "Model 5" "Model 6" "Model 7" "Model 8" "Model 9")  indicate("Party FE = *.party") /// 
			compress se  noomitted  interaction(" X ") dropped("Ref.") nogaps star(+ .10 * .05 ** .01 *** .001) ///	
			order(?.gender $personal $family $political_offices $party_position $inter_personal $party_level $controls )				
		
esttab model_survival7 model_survival8 model_survival9 model_survival10 model_survival11 model_survival12 model_survival13 , label mtitle("Model 1" "Model 2" "Model 3" "Model 4" "Model 5" "Model 6" "Model 7" "Model 8" "Model 9") /// 
			compress se  noomitted  interaction(" X ") dropped("Ref.") nogaps star(+ .10 * .05 ** .01 *** .001) ///	
			order(?.gender $personal $family $political_offices $party_position $inter_personal $party_level $controls )		

esttab model_survival6 model_survival14 model_survival13 model_survival15, label   mtitle("Model 1" "Model 2" "Model 3" "Model 4" )  indicate("Party FE = *.party") /// 
			compress se  noomitted  interaction(" X ") dropped("Ref.") nogaps star(+ .10 * .05 ** .01 *** .001) ///	
			order(?.gender $personal $family $political_offices $party_position $inter_personal $party_level $controls )	varwidth(30)		
			
* Appendix D: Tables 13 to 15

** Table 21
esttab  model_survival1 model_survival2 model_survival3 model_survival4 model_survival5 model_survival6 using "survival_regressions1.tex", replace ///
compress se noomitted  interaction(" X ") dropped("Ref.") nogaps star(* .05 ** .01 *** .001) ///	
mtitle("Model 1" "Model 2" "Model 3" "Model 4" "Model 5" "Model 6" "Model 7" "Model 8" "Model 9")  /// 
order(?.gender $personal $family $political_offices $party_position $inter_personal $party_level $controls )	///
label nonumbers booktabs longtable scalars("ll Log lik.")  alignment(D{.}{.}{-1}) indicate("Party FE = *.party") /// 
addnote("\begin{minipage}[t]{0.9\textwidth} Clustered standard errors by political party. Models including the variable childless are calculated using only PP and PSOE observations. \end{minipage}") ///
title("Determinants of survival in parties' NEC\label{table.survival_regressions1}")  // 

** Table 22
esttab  model_survival7 model_survival8 model_survival9 model_survival10 model_survival11 model_survival12 model_survival13 using "survival_regressions2.tex", replace ///
compress se noomitted  interaction(" X ") dropped("Ref.") nogaps star(* .05 ** .01 *** .001) ///	
mtitle("Model 1" "Model 2" "Model 3" "Model 4" "Model 5" "Model 6" "Model 7" "Model 8" "Model 9")  /// 
order(?.gender $personal $family $political_offices $party_position $inter_personal $party_level $controls )	///
label nonumbers booktabs longtable scalars("ll Log lik.")  alignment(D{.}{.}{-1})  /// 
addnote("\begin{minipage}[t]{0.9\textwidth} Clustered standard errors by political party. Models including the variable childless are calculated using only PP and PSOE observations. \end{minipage}") ///
title("Determinants of survival in parties' NEC (sub-sample)\label{table.survival_regressions2}")  // 

** Table 23
esttab  model_survival6 model_survival14 model_survival13 model_survival15 using "survival_regressions3.tex", replace ///
compress se noomitted  interaction(" X ") dropped("Ref.") nogaps star(* .05 ** .01 *** .001) ///	
mgroups("Full sample" "Sub-sample", pattern(0 0 1 1)) mtitle("Model 1" "Model 2" "Model 3" "Model 4" "Model 5" "Model 6" "Model 7" "Model 8" "Model 9")  ///
order(?.gender $personal $family $political_offices $party_position $inter_personal $party_level $controls )	///
label nonumbers booktabs longtable scalars("ll Log lik.")  alignment(D{.}{.}{-1}) indicate("Party FE = *.party") /// 
addnote("\begin{minipage}[t]{0.9\textwidth} Clustered standard errors by political party. Models including the variable childless are calculated using only PP and PSOE observations. \end{minipage}") ///
title("Heterogeneous effects by gender\label{table.survival_regressions3}")  // 

* Main text: Figure 3

* Full sample
** Baseline model
coefplot 	 	(model_survival6, pstyle(p1) msymbol(circle) mlcolor(black) mfcolor(black) msize(small)), title("(a.1) Baseline model") /// 
				keep(?.gender $personal $partisan_experience $political_offices $inter_personal $party_position $family ) 		///
			 	||,  xline(0, lcolor(black)) xtitle("Coefficient") scheme(plottig)    drop( _cons)   /// 
				order(1.gender $personal $family $political_offices $partisan_experience $inter_personal ) headings(1.gender = "{bf:Individual factors}" years_as_party_member_log = "{bf:Interpersonal resources}") ///
				name(portfolios1, replace) legend(off) ///  
				coeflabels(, wrap(45) notick interaction(" X ")) rename(.gender##?.age=age)  ytick(1.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5 9.5 10.5 11.5 12.5 , notick glstyle(grid)) fxsize(100) fysize(100) // 
** Interaction model
coefplot 	 	(model_survival14, label("Men") pstyle(p1) msymbol(diamond) mlcolor(black) mfcolor(black) msize(small) keep( $personal $political_offices $inter_personal $party_position $family )) 		///
				(model_survival14, label("Women") pstyle(p1) msymbol(triangle) mlcolor(gs8) mfcolor(gs8) msize(medsmall) ciopts(lcolor(gs8)) keep( 1.gender#?.age 1.gender#?.university_degree 1.gender#?.isei 1.gender#?.years_as_party_member_log 1.gender#?.youth_org 1.gender#?.seniority_log 1.gender#?.national_politics_experience_log 1.gender#?.leader_coincidence_log 1.gender#?.party_hardcore  1.gender#?.childless )) 		///
			 	||,  xline(0, lcolor(black)) xtitle("Coefficient") scheme(plottig)    drop( _cons) title("(a.2) Interaction model")  /// ciopts(lwidth(.5 ..) )  norecycle eform baselevels
				order( age 1.gender#?.age university_degree 1.gender#?.university_degree isei 1.gender#?.isei seniority_log 1.gender#?.seniority_log national_politics_experience_log 1.gender#?.national_politics_experience_log years_as_party_member_log 1.gender#?.years_as_party_member_log youth_org 1.gender#?.youth_org  leader_coincidence_log 1.gender#?.leader_coincidence_log party_hardcore 1.gender#?.party_hardcore childless 1.gender#?.childless ) ///
				headings(age = "{bf:Individual factors}" years_as_party_member_log = "{bf:Interpersonal resources}") ///
				name(portfolios2, replace) legend(rows(1) position(6)) fxsize(100) fysize(150) /// 
				coeflabels(	1.gender#?.age=" " ///
							1.gender#?.university_degree=" " ///
							1.gender#?.isei=" " ///
							1.gender#?.years_as_party_member_log=" " ///
							1.gender#?.youth_org=" " ///
							1.gender#?.seniority_log=" " ///
							1.gender#?.national_politics_experience_log=" " ///
							1.gender#?.leader_coincidence_log=" " ///
							1.gender#?.party_hardcore=" " ///
							1.gender#?.nato=" " ///
							1.gender#1.nec_election_mode="Appointed by the leader" ///
							1.gender#2.nec_election_mode="Elected in closed lists" ///							
							1.gender#3.nec_election_mode="Elected in open lists" ///							
							1.gender#?.gender_internal_rules="Female quota size (in prop)" ///
							1.gender#?.share_female_mps="Share of women in PPG" ///
							1.gender#?.nec_renewal2="Prop. of NEC renewed" ///
							1.gender#?.total_nec="NEC size" ///
							1.gender#?.left_wing="Left-wing party" ///
							1.gender#?.childless="Childless" ///
									, wrap(45) notick interaction(" X ")) rename(.gender##?.age=age)  ytick(1.5 3.5 5.5 7.5 9.5 11.5 13.5 15.5 17.5 19.5, notick glstyle(grid)) // 

* Sub-sample
** Baseline model
coefplot 	 	(model_survival13, pstyle(p1) msymbol(circle) mlcolor(black) mfcolor(black) msize(small)), title("(b.1) Baseline model") 		 /// 
				keep(?.gender $personal $political_offices $inter_personal $party_position $family ) 		///
			 	||,  xline(0, lcolor(black)) xtitle("Coefficient") scheme(plottig)    drop( _cons)   /// 
				order(1.gender $personal $family $political_offices $partisan_experience $inter_personal ) headings(1.gender = "{bf:Individual factors}" years_as_party_member_log = "{bf:Interpersonal resources}") ///
				name(portfolios3, replace) legend(off) ///  
				coeflabels(, wrap(45) notick interaction(" X ")) rename(.gender##?.age=age)  ytick(1.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5 9.5 10.5 11.5 12.5 13.5, notick glstyle(grid)) fxsize(100) fysize(100) // 
** Interaction model
coefplot 	 	(model_survival15, label("Men") pstyle(p1) msymbol(diamond) mlcolor(black) mfcolor(black) msize(small) keep( $personal $political_offices $inter_personal $party_position $family )) 		///
				(model_survival15, label("Women") pstyle(p1) msymbol(triangle) mlcolor(gs8) mfcolor(gs8) msize(medsmall) ciopts(lcolor(gs8)) keep( 1.gender#?.age 1.gender#?.university_degree 1.gender#?.isei 1.gender#?.childless 1.gender#?.years_as_party_member_log 1.gender#?.youth_org 1.gender#?.seniority_log 1.gender#?.national_politics_experience_log 1.gender#?.leader_coincidence_log 1.gender#?.childless 1.gender#?.party_hardcore )) 		///
			 	||,  xline(0, lcolor(black)) xtitle("Coefficient") scheme(plottig)    drop( _cons) title("(b.2) Interaction model")  /// 
				order( age 1.gender#?.age university_degree 1.gender#?.university_degree isei 1.gender#?.isei  childless 1.gender#?.childless seniority_log 1.gender#?.seniority_log national_politics_experience_log 1.gender#?.national_politics_experience_log years_as_party_member_log 1.gender#?.years_as_party_member_log youth_org 1.gender#?.youth_org leader_coincidence_log 1.gender#?.leader_coincidence_log  party_hardcore 1.gender#?.party_hardcore ) ///
				headings(age = "{bf:Individual factors}" years_as_party_member_log = "{bf:Interpersonal resources}") ///
				name(portfolios4, replace) legend(rows(1) position(6))  fxsize(100) fysize(150) /// 
				coeflabels(	1.gender#?.age=" " ///
							1.gender#?.university_degree=" " ///
							1.gender#?.isei=" " ///
							1.gender#?.years_as_party_member_log=" " ///
							1.gender#?.youth_org=" " ///
							1.gender#?.seniority_log=" " ///
							1.gender#?.national_politics_experience_log=" " ///
							1.gender#?.leader_coincidence_log=" " ///
							1.gender#?.party_hardcore=" " ///
							1.gender#?.nato=" " ///
							1.gender#1.nec_election_mode=" " ///
							1.gender#2.nec_election_mode=" " ///							
							1.gender#3.nec_election_mode=" " ///							
							1.gender#?.gender_internal_rules=" " ///
							1.gender#?.share_female_mps=" " ///
							1.gender#?.nec_renewal2=" " ///
							1.gender#?.total_nec=" " ///
							1.gender#?.left_wing=" " ///
							1.gender#?.childless=" " ///
									, wrap(45) notick interaction(" X ")) rename(.gender##?.age=age)  ytick(1.5 3.5 5.5 7.5 9.5 11.5 13.5 15.5 17.5 19.5 21.5, notick glstyle(grid)) // 
** All plots together																						
graph combine portfolios1 portfolios2 , cols(1) xsize(5) ysize(10) title("(a) Full sample:", size(small)) name(portfoliosa, replace) xcommon
graph combine portfolios3 portfolios4 , cols(1) xsize(5) ysize(10) title("(b) Sub-sample, PP & PSOE:", size(small)) name(portfoliosb, replace) xcommon
graph combine portfoliosa portfoliosb ,  cols(2) xsize(10) ysize(10) xcommon 
graph save "survival_model1.gph", replace
graph export "survival_model1.png", replace

** Appendix E, Table 19 and 20: Descriptive statistics for analysis 3

tabulate nec_election_mode, generate(selection_mode_)
label variable selection_mode_1 "Selection: Appointed by the leader"
label variable selection_mode_2 "Selection: Elected in closed lists"
label variable selection_mode_3 "Selection: Elected in open lists"
tabulate party, generate(party_)
label variable party_1 "Party: AP/PP"
label variable party_2 "Party: PSOE"
label variable party_3 "Party: IU"
label variable party_4 "Party: Podemos"
label variable party_5 "Party: C's"
label variable party_6 "Party: Vox"

* Full sample
eststo all: quietly estpost summarize ///
    gender $personal $partisan_experience $political_offices $party_position $inter_personal $party_level $controls /// 
	party_1 party_2 party_3 party_4 party_5 party_6

esttab all, ///
cells("mean( fmt(3)) sd( fmt(3)) min( fmt(3)) max( fmt(3))") ///
label compress // 

esttab all using "survival_descriptive1.tex", replace ///
cells("mean( fmt(3)) sd( fmt(3)) min( fmt(3)) max( fmt(3))") ///
label compress title("Descriptive statistics.") mtitle("Full sample") //

* Sub-sample
eststo all: quietly estpost summarize ///
    gender $personal $family 	$partisan_experience $political_offices $party_position $inter_personal $party_level $controls /// 
	party_1 party_2 if party<3402

esttab all, ///
cells("mean( fmt(3)) sd( fmt(3)) min( fmt(3)) max( fmt(3))") ///
label compress  //

esttab all using "survival_descriptive2.tex", replace ///
cells("mean( fmt(3)) sd( fmt(3)) min( fmt(3)) max( fmt(3))") ///
label compress title("Descriptive statistics, only PP \& PSOE subsample with family information.")  mtitle("Sub-sample") //

***************************************
*** Analysis 3 - Robustness checks  ***
***************************************

** Robustness 1 - Excluding ex-officio and appointed NEC members from the full sample (Appendix E, table 24)

* Regressions 
stcox  i.gender $personal_ $political_offices_ $party_position_ $inter_personal_ 					$party_level_ $controls_ $party_  if nato==0 ,  vce(cluster party)
eststo nato_robust1
stcox  i.gender##($personal_ $political_offices_ $inter_personal_	$party_position_				$party_level_ $controls_ $party_) if nato==0 ,  vce(cluster party)
eststo nato_robust2

stcox  i.gender $personal_ $political_offices_ $party_position_ $inter_personal_	$family_		$party_level_ $controls_  if party<3402 & nato==0 ,  vce(cluster party)
eststo nato_robust3
stcox  i.gender##($personal_ $political_offices_ $inter_personal_ $party_position_	$family_	$party_level_ $controls_ ) if party<3402 & nato==0 ,  vce(cluster party)
eststo nato_robust4

esttab nato_robust1 nato_robust2 nato_robust3 nato_robust4, label   mtitle("Model 1" "Model 2" "Model 3" "Model 4" )  indicate("Party FE = *.party") /// 
			compress se  noomitted  interaction(" X ") dropped("Ref.") nogaps star(+ .10 * .05 ** .01 *** .001) ///	
			order(?.gender $personal $family $political_offices $partisan_experience $party_position $inter_personal $party_level $controls )	

* Table 
esttab  nato_robust1 nato_robust2 nato_robust3 nato_robust4 using "survival_robust3.tex", replace ///
compress se noomitted  interaction(" X ") dropped("Ref.") nogaps star(* .05 ** .01 *** .001) ///	
mgroups("Full sample" "Sub-sample", pattern(0 0 1 1)) mtitle("Model 1" "Model 2" "Model 3" "Model 4" "Model 5" "Model 6" "Model 7" "Model 8" "Model 9")  ///
order(?.gender $personal $family $political_offices $partisan_experience $party_position $inter_personal $party_level $controls )	///
label nonumbers booktabs longtable scalars("ll Log lik.")  alignment(D{.}{.}{-1})  indicate("Party FE = *.party")  /// 
addnote("\begin{minipage}[t]{0.9\textwidth} Clustered standard errors by political party. Models including the variable childless are calculated using only PP and PSOE observations. \end{minipage}") ///
title("Survival in parties' NEC, robustness check 1: Excluding ex-officio and appointed NEC members.\label{table.survival_robust3}")  //

** Robustness 2 - Alternative operationalizations of male homosocial capital (Appendix E, tables 25 and 26)

* Regressions: Same region as leader 
stcox  i.gender $personal_ $partisan_experience_ $political_offices_ years_as_party_member_log youth_org leader_region_coincidence $party_position_ $party_level_ $controls_ $party_,  vce(cluster party)
eststo survival_robust1
stcox  i.gender##($personal_ $partisan_experience_ $political_offices_ c.years_as_party_member_log c.youth_org c.leader_region_coincidence $party_position_ $party_level_ $controls_ $party_),  vce(cluster party)
eststo survival_robust2

stcox  i.gender $personal_ $partisan_experience_ $political_offices_ years_as_party_member_log youth_org leader_region_coincidence $party_position_ $party_level_ $family_ $controls_  if party<3402,  vce(cluster party)
eststo survival_robust3
stcox  i.gender##($personal_ $partisan_experience_ $political_offices_ c.years_as_party_member_log c.youth_org c.leader_region_coincidence $party_position_ $party_level_ $family_ $controls_ ) if party<3402,  vce(cluster party)
eststo survival_robust4

* Regressions: Same biological cohort as leader (birth -/+5 years) 
stcox  i.gender $personal_ $partisan_experience_ $political_offices_ years_as_party_member_log youth_org leader_birth_coincidence $party_position_ $party_level_ $controls_ $party_,  vce(cluster party)
eststo survival_robust5
stcox  i.gender##($personal_ $partisan_experience_ $political_offices_ c.years_as_party_member_log c.youth_org c.leader_birth_coincidence $party_position_ $party_level_ $controls_ $party_),  vce(cluster party)
eststo survival_robust6

stcox  i.gender $personal_ $partisan_experience_ $political_offices_ years_as_party_member_log youth_org leader_birth_coincidence $party_position_ $party_level_ $family_ $controls_  if party<3402,  vce(cluster party)
eststo survival_robust7
stcox  i.gender##($personal_ $partisan_experience_ $political_offices_ c.years_as_party_member_log c.youth_org c.leader_birth_coincidence $party_position_ $party_level_ $family_ $controls_ ) if party<3402,  vce(cluster party)
eststo survival_robust8

esttab model_survival6 model_survival14 survival_robust1 survival_robust2 survival_robust5 survival_robust6 , ///
			label compress se  noomitted  interaction(" X ") dropped("Ref.") nogaps star(+ .10 * .05 ** .01 *** .001)	indicate("Party FE = *.party") /// 
			order(?.gender $personal $family $political_offices $partisan_experience $party_position $inter_personal $party_level $controls )	//			

esttab model_survival13 model_survival15 survival_robust3 survival_robust4 survival_robust7 survival_robust8 , replace ///
			label compress se  noomitted  interaction(" X ") dropped("Ref.") nogaps star(+ .10 * .05 ** .01 *** .001) ///	
			order(?.gender $personal $family $political_offices $partisan_experience $party_position $inter_personal $party_level $controls )	//			

* Tables
esttab model_survival6 model_survival14  survival_robust1 survival_robust2 survival_robust5 survival_robust6 using "robust_analysis3_interpersonal_operatinalization_fs.tex" , replace ///
compress se  noomitted  interaction(" X ") dropped("Ref.") nogaps star(* .05 ** .01 *** .001) ///	
mtitle("Years (log)" "--" "Same region" "--" "Same generation" "--") ///	
label nonumbers booktabs longtable pr2 scalars("ll Log lik.")  alignment(D{.}{.}{-1})  /// 
addnote("\begin{minipage}[t]{0.9\textwidth} Clustered standard errors by political party. Models including the variable childless are calculated using only PP and PSOE observations. \end{minipage}") ///
title("Survival in parties' NEC, robustness check 2: Alternative operationalizations of male homosocial capital (full sample).\label{table.portfolios_allocation_regressions4}") ///
order(*.gender $personal $partisan_experience $political_offices $controls ) 

esttab model_survival13 model_survival15  survival_robust3 survival_robust4 survival_robust7 survival_robust8  using "robust_analysis3_interpersonal_operatinalization_ss.tex" , replace ///
compress se  noomitted  interaction(" X ") dropped("Ref.") nogaps star(* .05 ** .01 *** .001) ///	
mtitle("Years (log)" "--" "Same region" "--" "Same generation" "--") ///	
label nonumbers booktabs longtable pr2 scalars("ll Log lik.")  alignment(D{.}{.}{-1})  /// 
addnote("\begin{minipage}[t]{0.9\textwidth} Clustered standard errors by political party. Models including the variable childless are calculated using only PP and PSOE observations. \end{minipage}") ///
title("Survival in parties' NEC, robustness check 2: Alternative operationalizations of male homosocial capital (sub-sample).\label{table.portfolios_allocation_regressions5}") ///
order(*.gender $personal $partisan_experience $political_offices $controls ) 

*******************************************************************************
*** Analysis 3 - Further evidence for the mechanisms (three-way interaction ***
*******************************************************************************

** Appendix F

* Three-way interaction, full sample.
stcox  i.gender $personal_ $political_offices_ $inter_personal_	$party_position_				$party_level_ $controls_ $party_ i.gender##c.leader_coincidence_log##i.leader_birth_coincidence,  vce(cluster party)
eststo mechanism3
* Three-way interaction, sub-sample.
stcox  i.gender $personal_ $family_ $political_offices_ $inter_personal_	$party_position_				$party_level_ $controls_ $party_ i.gender##c.leader_coincidence_log##i.leader_birth_coincidence if party<3402,  vce(cluster party)
eststo mechanism4

esttab mechanism3 mechanism4  , replace ///
			label compress se  noomitted  interaction(" X ") dropped("Ref.") nogaps star(+ .10 * .05 ** .01 *** .001) ///	
			order(?.gender $personal $family $political_offices $partisan_experience $party_position $inter_personal $party_level $controls )	//			

* Tables
esttab  model_survival6 mechanism3 model_survival13 mechanism4 using "mechanism2.tex", replace ///
compress se noomitted  interaction(" X ") dropped("Ref.") nogaps star(+ 0.10 * 0.05 ** 0.01 *** 0.001) ///	
mgroups("Full sample" "Sub-sample", pattern(0 0 1 1)) mtitle("Model 1" "Model 2" "Model 3" "Model 4" "Model 5" "Model 6" "Model 7" "Model 8" "Model 9")  ///
order(?.gender $personal $family $political_offices $partisan_experience $party_position $inter_personal $party_level $controls )	///
label nonumbers booktabs longtable scalars("ll Log lik.")  alignment(D{.}{.}{-1})  indicate("Party FE = *.party")  /// 
addnote("\begin{minipage}[t]{0.9\textwidth} Clustered standard errors by political party. Models including the variable childless are calculated using only PP and PSOE observations. \end{minipage}") ///
title("Survival in parties' NEC, exploring the possible mechanisms 2.\label{table.mechanism2}")  // 

* Margins plot
* Full sample
stcox  i.gender $personal_ $political_offices_ $inter_personal_	$party_position_				$party_level_ $controls_ $party_ i.gender##c.leader_coincidence_log##i.leader_birth_coincidence,  vce(cluster party)
margins, dydx(leader_coincidence_log) over(gender) at(leader_birth_coincidence=(0(1)1))
marginsplot, name(mechanism3, replace) yline(0) recast(scatter) recastci(rcap) ciopts(msize(vlarge)) scheme(plotplain) level(95) xscale(range(-0.2 1.2)) xlabel(0 1) plot1opts(mcolor(black) msymbol(circle) msize(medium)) plot2opts(mcolor(gs10) msymbol(triangle) msize(medium)) xtitle("") ytitle("Effects on Pr(Exiting NEC)") title("Full sample") legend(rows(1))
* Sub-sample
stcox  i.gender $personal_ $family_ $political_offices_ $inter_personal_	$party_position_				$party_level_ $controls_ $party_ i.gender##c.leader_coincidence_log##i.leader_birth_coincidence if party<3402,  vce(cluster party)
margins, dydx(leader_coincidence_log) over(gender) at(leader_birth_coincidence=(0(1)1))
marginsplot, name(mechanism4, replace) yline(0) recast(scatter) recastci(rcap) ciopts(msize(vlarge)) scheme(plotplain) level(95) xscale(range(-0.2 1.2)) xlabel(0 1) plot1opts(mcolor(black) msymbol(circle) msize(medium)) plot2opts(mcolor(gs10) msymbol(triangle) msize(medium)) xtitle("") ytitle("Effects on Pr(Exiting NEC)") title("Sub-sample") legend(rows(1)) 
* Together
grc1leg mechanism3 mechanism4, title("AME of coinciding with the leader on exiting NEC") ycommon
graph export "mechanism2.png", replace


